"""
Case Type   : 共享存储-工具-pg_controldata
Case Name   : 版本信息显示
Create At   : 2023/4/11
Owner       : opentestcase019
Description :
    1.版本信息显示
      pg_controldata -V/--version
Expect      :
    1.版本信息显示正常
History     :
"""
import os
import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common


class ShareStorageTool(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f"-----{os.path.basename(__file__)} start-----")
        self.primary_node = Node('PrimaryDbUser')
        self.common = Common()

    def test_sharestorage_tool(self):
        step1 = "-----step1:版本信息显示;expect:版本信息显示正常-----"
        self.logger.info(step1)
        execute_cmd = f"source {macro.DB_ENV_PATH};pg_controldata -V"
        self.logger.info(execute_cmd)
        execute_msg = self.common.get_sh_result(self.primary_node, execute_cmd)
        self.assertIn("pg_controldata (openGauss", execute_msg,
                      "执行失败" + step1)
        execute_cmd = f"source {macro.DB_ENV_PATH};pg_controldata --version"
        self.logger.info(execute_cmd)
        execute_msg = self.common.get_sh_result(self.primary_node, execute_cmd)
        self.assertIn("pg_controldata (openGauss", execute_msg,
                      "执行失败" + step1)

    def tearDown(self):
        self.logger.info("-----无需环境清理-----")
        self.logger.info(f"-----{os.path.basename(__file__)} end-----")
